import baseInfo from '@/default/index'
// 跳转到新的页面
import router from "@/router";
// import {getSessionItem, setSessionItem} from "@/utils/auth";
import Vue from "vue";
import {removeSessionItem} from "@/utils/auth";
export function uniJumpRoute(path,query){
    if (path===-1   ){
        router.go(-1)
    }else{
        router.push({path:path,query}).catch(err=>{})
    }
}

// 防止重复提交的
Vue.directive('debounce', {
    inserted(el, binding) {
        let throttleTime = parseInt(binding.value) || 2000
        el.addEventListener('click', () => {
            if (!el.disabled) {
                el.disabled = true
                setTimeout(() => {
                    el.disabled = false
                }, throttleTime)
            }
        })
    }
})


// 路由跳转
Vue.directive('routers', {
    inserted(el, data) {
        el.addEventListener('click', () => {
            uniJumpRoute(data.value.path,data.value.query)
            removeSessionItem('pay')
        })
    }
})


// 颜色
Vue.directive('color',{
    inserted(el,data){

        let theme ='#fff'
        setTimeout(()=>{
            switch (data.value){
                case 'border':{
                    el.style.border = `1.5px solid ${baseInfo.borderColor}`
                    break
                }

                case 'bgk':{
                    el.style.backgroundColor = baseInfo.bgkColor
                    break
                }
                case 'bgkImg':{
                    el.style.background = `url(${baseInfo.bgkImg}) no-repeat`
                    el.style.backgroundSize='100% 100%'
                    break
                }
                case 'font':{
                    el.style.color = baseInfo.fontColor
                    break
                }
                case 'line':{
                    el.style.backgroundImage = `linear-gradient(to bottom, ${baseInfo.bgkColor} 0%, #f5efef 100%)`
                    break
                }
                default:{
                    el.style.color = baseInfo.fontColor
                    break
                }
            }
        },100)

    }
})